'----------------------------------------------
' Name: Ali Karbassi & Brian Gresl
' Date: January 25, 2007
' Description: Project 1
'              form frmShow
'----------------------------------------------
Public Class frmShow

	''' <summary>
   ''' Hides the form.
	''' </summary>
	''' <param name="sender"></param>
	''' <param name="e"></param>
	''' <remarks></remarks>
   Private Sub btnBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBack.Click

      Me.Hide()

   End Sub

	''' <summary>
   ''' Exits the application.
	''' </summary>
	''' <param name="sender"></param>
	''' <param name="e"></param>
	''' <remarks></remarks>
   Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click

      Application.Exit()

   End Sub

	''' <summary>
   ''' Calls ArrangeButtons and FontStyleButtons.
	''' </summary>
	''' <param name="sender"></param>
	''' <param name="e"></param>
	''' <remarks></remarks>
   Private Sub frmShow_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _
   MyBase.Resize

      ArrangeButtons()
      FontStyleButtons()

   End Sub

   ''' <summary>
   ''' The sub displays all buttons on the form as required.
   ''' </summary>
   ''' <remarks>Done in 5 lines of code (not counting your 100 character limit wrap-arounds).</remarks>
   Friend Sub ArrangeButtons()

      Dim x As Integer = (Me.ClientSize.Width - (2 * leftWidth) - (btnList.Count * btnSize.Width)) _
                           / (btnList.Count + 1)

      For Each key As String In btnList.Keys

         CType(btnList(key), Button).Left = leftWidth + x * (btnList.IndexOfKey(key) + 1) + _
            (btnSize.Width * btnList.IndexOfKey(key))

         CType(btnList(key), Button).Top = ((Me.ClientSize.Height - mnuStrip.Height) / 2) + _
            (CType(btnList(key), Button).Height / 2)

      Next

   End Sub

   ''' <summary>
   ''' Sets the font style WITHOUT using if or select case statements.
   ''' </summary>
   ''' <remarks>Uses math :)</remarks>
   Friend Sub FontStyleButtons()

      Dim bold As Integer = CType(chkBold.Tag, Integer) * Math.Abs(CType(chkBold.Checked, Integer))
      Dim italic As Integer = CType(chkItalic.Tag, Integer) * Math.Abs(CType(chkItalic.Checked, Integer))
      Dim underline As Integer = CType(chkUnderline.Tag, Integer) * Math.Abs(CType(chkUnderline.Checked, _
         Integer))

      Dim fontstylenumber As Integer = bold + italic + underline

      For Each key As String In btnList.Keys

         CType(btnList(key), Button).Font = New System.Drawing.Font(CType(btnList(key), Button).Font, _
            fontstylenumber)

      Next

   End Sub

   ''' <summary>
   ''' Handles the font style menu clicks.
   ''' </summary>
   ''' <param name="sender"></param>
   ''' <param name="e"></param>
   ''' <remarks></remarks>
   Private Sub FontMenuCheck(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _
   chkBold.Click, chkItalic.Click, chkUnderline.Click

      FontStyleButtons()

   End Sub

   ''' <summary>
   ''' Shows the new button's information.
   ''' </summary>
   ''' <param name="sender"></param>
   ''' <param name="e"></param>
   ''' <remarks>We love you Qi!</remarks>
   Friend Sub btnHandler(ByVal sender As System.Object, ByVal e As System.EventArgs)

      Dim key As String = btnList.GetKey(btnList.IndexOfValue(CType(sender, Button)))
      Dim caption As String = CType(sender, Button).Text

      MsgBox("My Key   : " & key & vbCrLf & "My Caption: " & caption, MsgBoxStyle.OkOnly)

   End Sub

End Class